//事件代理


export function componentProxy(name,opts) {

    opts.mixins=[
        {
            created() {
                // this.$on(name,opts.callback)
                console.log("内置组件",this.$attrs)
                for(let attr in this.$attrs){
                    if(!/^bind/.test(attr)){
                        continue;
                    }
                    if(!this.$attrs[attr]){
                        continue;
                    }

                    const eventName=attr.replace(/^bind/,"");
                    const methodName=this.$attrs[attr];
                    // console.log("_bridgeInfo:",this.$vnode.context._bridgeInfo)
                    const {id}=this.$vnode.context._bridgeInfo;
                    
                    this.$on(eventName,(param)=>{
                        console.log("事件代理",methodName,param,id)
                        //向原生层发送消息
                        window.parent.postMessage({
                            type:'trrigerEvent',
                            body:{
                                methodName,
                                id,
                                param
                            }
                        },'*');
                    })
                }
            }
        }
    ]
    Vue.component(name,opts)
}